package opc_service

import (
	"beta/pkg/e"
	"beta/pkg/logger"
	"beta/pkg/util"
	"time"
)

type Audit struct {
	CustomerID string `json:"customerId"`
	DepositID  string `json:"depositId"`
	AuditFlag  bool   `json:"auditFlag"`
	Remark     string `json:"remark"`
}

func (opc OpcService) Audit(couponDepositId string, flag bool) error {
	host := opc.Hosts[appName].AppDomain
	url := host + "/opc/v1/deposit/audit"


	audit := Audit{
		CustomerID: opc.CustomerID,
		DepositID:  couponDepositId,
		AuditFlag:  flag,
		Remark:     "beta自动审核",
	}

	logger.ZapLogger.Infow("【卡券审核】", "请求参数", audit, "traceId", opc.TraceId)
	cookie := util.GetCookie(util.BossCookieName, opc.Token)
	httpClient := util.NewHttpClientWithCookie(3 * time.Second, cookie).R()
	resp, respErr := httpClient.SetHeaders(e.GetHeaderMap(e.JsonHeader)).SetBody(audit).Post(url)

	logger.ZapLogger.Infow("【卡券审核】", "请求结果", resp, "traceId", opc.TraceId)
	if respErr != nil {
		return respErr
	}

	return nil
}